package com.sdp.right.db.sys_flow_template_version.service.impl;

import org.springframework.stereotype.Service;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sdp.right.db.sys_flow_template_version.mapper.SysFlowTemplateVersionMapper;
import com.sdp.right.db.sys_flow_template_version.service.ISysFlowTemplateVersionService;
import com.sdp.right.entity.SysFlowTemplate;
import com.sdp.right.entity.SysFlowTemplateVersion;
import com.sdp.right.service.RemoveSystemService;

import cn.hutool.core.bean.BeanUtil;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zsp
 * @since 2024-07-10
 */
@Service
@DS(value="right")
public class SysFlowTemplateVersionServiceImpl extends ServiceImpl<SysFlowTemplateVersionMapper, SysFlowTemplateVersion> implements ISysFlowTemplateVersionService,RemoveSystemService{

	@Override
	public SysFlowTemplateVersion createFlowTemplateVersion(SysFlowTemplate sysFlowTemplate) {
		SysFlowTemplateVersion sysFlowTemplateVersion = BeanUtil.toBean(sysFlowTemplate, SysFlowTemplateVersion.class);
		sysFlowTemplateVersion.setTemplateVersion(sysFlowTemplate.getTemplateVersion());
		sysFlowTemplateVersion.setKeyId(null);
		save(sysFlowTemplateVersion);
		return sysFlowTemplateVersion;
	}

	@Override
	public void removeBySystemNo(String systemNo) {
		LambdaQueryWrapper<SysFlowTemplateVersion> queryWrapper = new LambdaQueryWrapper<>();
		queryWrapper.eq(SysFlowTemplateVersion::getSystemNo, systemNo);
		remove(queryWrapper);
		
	}

	@Override
	public void clearHisFlowTemplateVersion(String version,String templateNo) {
		LambdaQueryWrapper<SysFlowTemplateVersion> queryWrapper = new LambdaQueryWrapper<>();
		queryWrapper.ne(SysFlowTemplateVersion::getTemplateVersion, version);
		queryWrapper.eq(SysFlowTemplateVersion::getTemplateNo, templateNo);
		remove(queryWrapper);
	}

	@Override
	public void removeFlowTemplateVersionByTemplateNo(String templateNo) {
		LambdaQueryWrapper<SysFlowTemplateVersion> queryWrapper = new LambdaQueryWrapper<>();
		queryWrapper.eq(SysFlowTemplateVersion::getTemplateNo, templateNo);
		remove(queryWrapper);
		
	}

	@Override
	public SysFlowTemplateVersion queryFlowTemplateVersion(String templateNo,String templateVersion) {
		LambdaQueryWrapper<SysFlowTemplateVersion> queryWrapper = new LambdaQueryWrapper<>();
		queryWrapper.eq(SysFlowTemplateVersion::getTemplateNo, templateNo);
		queryWrapper.eq(SysFlowTemplateVersion::getTemplateVersion, templateVersion);
		return getOne(queryWrapper,false);
	}
	
	

}
